Emmett Stralka
August 29, 2024
Initial setup and testing of the microcontroller development board, establishing the foundation for embedded systems development
Lab 1 focuses on the initial setup and testing of the microcontroller development board, establishing the foundation for embedded systems development. This lab introduces students to the hardware components, development environment, and basic testing procedures essential for successful completion of subsequent labs.
#include <stdint.h>
#define LED_PIN (1 << 5) // Example: LED connected to GPIO Pin 5
#define GPIO_PORT_BASE 0x40020000 // Example: Base address for GPIO Port A
#define GPIO_DIR_REG *(volatile uint32_t *)(GPIO_PORT_BASE + 0x04) // Direction Register
#define GPIO_OUT_REG *(volatile uint32_t *)(GPIO_PORT_BASE + 0x14) // Output Data Register
void delay(volatile uint32_t count) {
while (count--);
}
int main(void) {
// Set LED pin as output
GPIO_DIR_REG |= LED_PIN;
while (1) {
// Turn LED on
GPIO_OUT_REG |= LED_PIN;
delay(1000000); // Adjust for desired delay
// Turn LED off
GPIO_OUT_REG &= ~LED_PIN;
delay(1000000); // Adjust for desired delay
}
}The “Blinky LED” program serves as the “Hello World” of embedded systems. It involves: - GPIO Configuration: Setting a General Purpose Input/Output pin as an output - Register Manipulation: Directly writing to hardware registers to control the LED - Basic Delay Loop: Implementing a software delay for visual effect
For Lab 1, performance optimization is less critical than functional verification. However, understanding the direct register access versus library functions (e.g., HAL_GPIO_TogglePin) is a foundational concept for future optimization. Direct register access, as shown in the example, offers maximum control and minimal overhead.
Upon successful completion of Lab 1, students will have a fully assembled and tested development board, a functional programming environment, and the ability to deploy basic embedded code. This lab lays the groundwork for more complex embedded systems projects.